package com.summer.aop.Proxy.jdk;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.Modifier;

import junit.framework.TestCase;
import sun.misc.ProxyGenerator;

public class JdkProxyBuildTest extends TestCase{
	
	public void test() throws IOException{
		buildProxyClass();
	}
	
	public void buildProxyClass() throws IOException{
		int accessFlags = Modifier.PUBLIC | Modifier.FINAL;
		byte[] proxyClassFile = ProxyGenerator.generateProxyClass("UserService$proxy", 
				new Class[]{TestObj.class}, accessFlags);
		
		String fileName = "C:/summer/UserService$proxy.class";
		File file = new File(fileName);
		FileOutputStream fileOut = new FileOutputStream(file);
		fileOut.write(proxyClassFile);
		fileOut.close();
		
	}
	
}
